package com.chinda.common.config.filter;

import com.chinda.common.filter.GlobalExceptionFilter;
import lombok.AllArgsConstructor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Wang Chinda
 * @date 2021/6/5
 */
@Configuration
@AllArgsConstructor
public class FilterConfiguration {

    private final GlobalExceptionFilter globalExceptionFilter;

    @Bean
    public FilterRegistrationBean<GlobalExceptionFilter> registrationGlobalExceptionFilter() {
        FilterRegistrationBean<GlobalExceptionFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(globalExceptionFilter);
        registration.addUrlPatterns("/*");
        registration.setName("globalExceptionFilter");
        registration.setOrder(Integer.MIN_VALUE);
        return registration;
    }
}
